from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-10-29 14:02:26.354279
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 29, Oct, 2022
Time: 14:02:32
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.8520
Nobs: 824.000 HQIC: -51.1694
Log likelihood: 10730.3 FPE: 4.91638e-23
AIC: -51.3669 Det(Omega_mle): 4.41059e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.291381 0.051475 5.661 0.000
L1.Burgenland 0.108867 0.035088 3.103 0.002
L1.Kärnten -0.106693 0.018692 -5.708 0.000
L1.Niederösterreich 0.210650 0.073421 2.869 0.004
L1.Oberösterreich 0.103188 0.070312 1.468 0.142
L1.Salzburg 0.249351 0.037318 6.682 0.000
L1.Steiermark 0.036766 0.048881 0.752 0.452
L1.Tirol 0.107105 0.039672 2.700 0.007
L1.Vorarlberg -0.057555 0.034110 -1.687 0.092
L1.Wien 0.061229 0.062776 0.975 0.329
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.064059 0.106414 0.602 0.547
L1.Burgenland -0.032760 0.072537 -0.452 0.652
L1.Kärnten 0.047521 0.038642 1.230 0.219
L1.Niederösterreich -0.172862 0.151781 -1.139 0.255
L1.Oberösterreich 0.385073 0.145355 2.649 0.008
L1.Salzburg 0.286517 0.077146 3.714 0.000
L1.Steiermark 0.104424 0.101052 1.033 0.301
L1.Tirol 0.314561 0.082012 3.836 0.000
L1.Vorarlberg 0.025041 0.070514 0.355 0.723
L1.Wien -0.014958 0.129775 -0.115 0.908
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189447 0.026423 7.170 0.000
L1.Burgenland 0.090720 0.018011 5.037 0.000
L1.Kärnten -0.008509 0.009595 -0.887 0.375
L1.Niederösterreich 0.264631 0.037687 7.022 0.000
L1.Oberösterreich 0.125553 0.036092 3.479 0.001
L1.Salzburg 0.048168 0.019155 2.515 0.012
L1.Steiermark 0.016991 0.025091 0.677 0.498
L1.Tirol 0.094873 0.020364 4.659 0.000
L1.Vorarlberg 0.059192 0.017509 3.381 0.001
L1.Wien 0.119920 0.032223 3.722 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.104523 0.027093 3.858 0.000
L1.Burgenland 0.044968 0.018468 2.435 0.015
L1.Kärnten -0.016373 0.009838 -1.664 0.096
L1.Niederösterreich 0.193406 0.038643 5.005 0.000
L1.Oberösterreich 0.294548 0.037007 7.959 0.000
L1.Salzburg 0.116270 0.019641 5.920 0.000
L1.Steiermark 0.099629 0.025727 3.872 0.000
L1.Tirol 0.117684 0.020880 5.636 0.000
L1.Vorarlberg 0.071274 0.017953 3.970 0.000
L1.Wien -0.026575 0.033040 -0.804 0.421
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.119842 0.049291 2.431 0.015
L1.Burgenland -0.049919 0.033599 -1.486 0.137
L1.Kärnten -0.040599 0.017899 -2.268 0.023
L1.Niederösterreich 0.168650 0.070305 2.399 0.016
L1.Oberösterreich 0.139543 0.067328 2.073 0.038
L1.Salzburg 0.284099 0.035734 7.950 0.000
L1.Steiermark 0.034127 0.046807 0.729 0.466
L1.Tirol 0.166384 0.037988 4.380 0.000
L1.Vorarlberg 0.106267 0.032662 3.254 0.001
L1.Wien 0.073331 0.060112 1.220 0.223
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056654 0.038974 1.454 0.146
L1.Burgenland 0.039833 0.026567 1.499 0.134
L1.Kärnten 0.050249 0.014153 3.551 0.000
L1.Niederösterreich 0.225448 0.055590 4.056 0.000
L1.Oberösterreich 0.282699 0.053237 5.310 0.000
L1.Salzburg 0.052537 0.028255 1.859 0.063
L1.Steiermark -0.008709 0.037010 -0.235 0.814
L1.Tirol 0.151382 0.030037 5.040 0.000
L1.Vorarlberg 0.070930 0.025826 2.746 0.006
L1.Wien 0.079803 0.047530 1.679 0.093
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.171336 0.046582 3.678 0.000
L1.Burgenland -0.005214 0.031753 -0.164 0.870
L1.Kärnten -0.061425 0.016915 -3.631 0.000
L1.Niederösterreich -0.083227 0.066441 -1.253 0.210
L1.Oberösterreich 0.193703 0.063628 3.044 0.002
L1.Salzburg 0.057190 0.033770 1.693 0.090
L1.Steiermark 0.228942 0.044235 5.176 0.000
L1.Tirol 0.495647 0.035901 13.806 0.000
L1.Vorarlberg 0.050812 0.030867 1.646 0.100
L1.Wien -0.045894 0.056808 -0.808 0.419
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.152841 0.053400 2.862 0.004
L1.Burgenland -0.010996 0.036400 -0.302 0.763
L1.Kärnten 0.065631 0.019391 3.385 0.001
L1.Niederösterreich 0.200464 0.076166 2.632 0.008
L1.Oberösterreich -0.058561 0.072941 -0.803 0.422
L1.Salzburg 0.217942 0.038713 5.630 0.000
L1.Steiermark 0.114014 0.050709 2.248 0.025
L1.Tirol 0.078961 0.041155 1.919 0.055
L1.Vorarlberg 0.125560 0.035385 3.548 0.000
L1.Wien 0.115790 0.065123 1.778 0.075
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.350283 0.031150 11.245 0.000
L1.Burgenland 0.006383 0.021234 0.301 0.764
L1.Kärnten -0.023716 0.011311 -2.097 0.036
L1.Niederösterreich 0.224282 0.044430 5.048 0.000
L1.Oberösterreich 0.174766 0.042549 4.107 0.000
L1.Salzburg 0.047722 0.022583 2.113 0.035
L1.Steiermark -0.016398 0.029580 -0.554 0.579
L1.Tirol 0.109860 0.024007 4.576 0.000
L1.Vorarlberg 0.074275 0.020641 3.598 0.000
L1.Wien 0.053585 0.037988 1.411 0.158
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041854 0.153150 0.190634 0.160324 0.125574 0.116380 0.066467 0.227835
Kärnten 0.041854 1.000000 -0.002173 0.129728 0.042414 0.096885 0.429083 -0.052929 0.101338
Niederösterreich 0.153150 -0.002173 1.000000 0.337496 0.157142 0.300827 0.113321 0.183971 0.329695
Oberösterreich 0.190634 0.129728 0.337496 1.000000 0.234617 0.333174 0.175222 0.173904 0.264388
Salzburg 0.160324 0.042414 0.157142 0.234617 1.000000 0.147695 0.132158 0.149608 0.137845
Steiermark 0.125574 0.096885 0.300827 0.333174 0.147695 1.000000 0.154724 0.141745 0.080220
Tirol 0.116380 0.429083 0.113321 0.175222 0.132158 0.154724 1.000000 0.116128 0.157540
Vorarlberg 0.066467 -0.052929 0.183971 0.173904 0.149608 0.141745 0.116128 1.000000 0.008335
Wien 0.227835 0.101338 0.329695 0.264388 0.137845 0.080220 0.157540 0.008335 1.000000